from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-12-24 14:02:32.021741
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 24, Dec, 2022
Time: 14:02:38
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -51.2931
Nobs: 880.000 HQIC: -51.5950
Log likelihood: 11636.1 FPE: 3.24629e-23
AIC: -51.7820 Det(Omega_mle): 2.93239e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297381 0.049595 5.996 0.000
L1.Burgenland 0.105999 0.033946 3.123 0.002
L1.Kärnten -0.106824 0.018233 -5.859 0.000
L1.Niederösterreich 0.213341 0.071207 2.996 0.003
L1.Oberösterreich 0.084419 0.067368 1.253 0.210
L1.Salzburg 0.250200 0.036037 6.943 0.000
L1.Steiermark 0.030704 0.047338 0.649 0.517
L1.Tirol 0.127153 0.038518 3.301 0.001
L1.Vorarlberg -0.062095 0.033132 -1.874 0.061
L1.Wien 0.064045 0.060087 1.066 0.286
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063843 0.101935 0.626 0.531
L1.Burgenland -0.009860 0.069771 -0.141 0.888
L1.Kärnten 0.049284 0.037474 1.315 0.188
L1.Niederösterreich -0.173196 0.146355 -1.183 0.237
L1.Oberösterreich 0.362013 0.138464 2.614 0.009
L1.Salzburg 0.286111 0.074069 3.863 0.000
L1.Steiermark 0.108730 0.097295 1.118 0.264
L1.Tirol 0.319067 0.079167 4.030 0.000
L1.Vorarlberg 0.024690 0.068097 0.363 0.717
L1.Wien -0.024752 0.123500 -0.200 0.841
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.200237 0.025724 7.784 0.000
L1.Burgenland 0.090507 0.017608 5.140 0.000
L1.Kärnten -0.009125 0.009457 -0.965 0.335
L1.Niederösterreich 0.267785 0.036934 7.250 0.000
L1.Oberösterreich 0.111295 0.034943 3.185 0.001
L1.Salzburg 0.053465 0.018692 2.860 0.004
L1.Steiermark 0.015963 0.024554 0.650 0.516
L1.Tirol 0.102476 0.019979 5.129 0.000
L1.Vorarlberg 0.056644 0.017185 3.296 0.001
L1.Wien 0.111795 0.031167 3.587 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.104380 0.026388 3.956 0.000
L1.Burgenland 0.047390 0.018062 2.624 0.009
L1.Kärnten -0.017051 0.009701 -1.758 0.079
L1.Niederösterreich 0.197548 0.037888 5.214 0.000
L1.Oberösterreich 0.279078 0.035845 7.786 0.000
L1.Salzburg 0.117624 0.019174 6.134 0.000
L1.Steiermark 0.099930 0.025187 3.968 0.000
L1.Tirol 0.127364 0.020494 6.215 0.000
L1.Vorarlberg 0.069780 0.017629 3.958 0.000
L1.Wien -0.026910 0.031971 -0.842 0.400
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.131604 0.047624 2.763 0.006
L1.Burgenland -0.054133 0.032597 -1.661 0.097
L1.Kärnten -0.037053 0.017508 -2.116 0.034
L1.Niederösterreich 0.166496 0.068377 2.435 0.015
L1.Oberösterreich 0.133582 0.064691 2.065 0.039
L1.Salzburg 0.290550 0.034605 8.396 0.000
L1.Steiermark 0.034296 0.045456 0.754 0.451
L1.Tirol 0.161973 0.036987 4.379 0.000
L1.Vorarlberg 0.107827 0.031815 3.389 0.001
L1.Wien 0.066430 0.057699 1.151 0.250
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061264 0.037761 1.622 0.105
L1.Burgenland 0.039032 0.025846 1.510 0.131
L1.Kärnten 0.049928 0.013882 3.597 0.000
L1.Niederösterreich 0.227573 0.054216 4.198 0.000
L1.Oberösterreich 0.267470 0.051293 5.215 0.000
L1.Salzburg 0.059879 0.027438 2.182 0.029
L1.Steiermark -0.006388 0.036042 -0.177 0.859
L1.Tirol 0.157438 0.029327 5.368 0.000
L1.Vorarlberg 0.069068 0.025226 2.738 0.006
L1.Wien 0.075463 0.045749 1.649 0.099
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185564 0.045273 4.099 0.000
L1.Burgenland 0.018339 0.030988 0.592 0.554
L1.Kärnten -0.060155 0.016644 -3.614 0.000
L1.Niederösterreich -0.094168 0.065001 -1.449 0.147
L1.Oberösterreich 0.174501 0.061496 2.838 0.005
L1.Salzburg 0.061222 0.032896 1.861 0.063
L1.Steiermark 0.230486 0.043212 5.334 0.000
L1.Tirol 0.488030 0.035161 13.880 0.000
L1.Vorarlberg 0.051320 0.030244 1.697 0.090
L1.Wien -0.053375 0.054850 -0.973 0.330
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158424 0.051361 3.084 0.002
L1.Burgenland 0.000224 0.035155 0.006 0.995
L1.Kärnten 0.066432 0.018882 3.518 0.000
L1.Niederösterreich 0.202129 0.073743 2.741 0.006
L1.Oberösterreich -0.070409 0.069767 -1.009 0.313
L1.Salzburg 0.220954 0.037321 5.920 0.000
L1.Steiermark 0.112484 0.049024 2.294 0.022
L1.Tirol 0.085057 0.039890 2.132 0.033
L1.Vorarlberg 0.123462 0.034312 3.598 0.000
L1.Wien 0.102913 0.062227 1.654 0.098
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360043 0.030409 11.840 0.000
L1.Burgenland 0.007137 0.020814 0.343 0.732
L1.Kärnten -0.025635 0.011179 -2.293 0.022
L1.Niederösterreich 0.228619 0.043660 5.236 0.000
L1.Oberösterreich 0.153604 0.041306 3.719 0.000
L1.Salzburg 0.052681 0.022096 2.384 0.017
L1.Steiermark -0.016502 0.029024 -0.569 0.570
L1.Tirol 0.122437 0.023617 5.184 0.000
L1.Vorarlberg 0.071022 0.020314 3.496 0.000
L1.Wien 0.048248 0.036842 1.310 0.190
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.038620 0.161025 0.180688 0.168891 0.143218 0.127724 0.065947 0.218916
Kärnten 0.038620 1.000000 0.001539 0.132064 0.026938 0.099281 0.432460 -0.049306 0.100833
Niederösterreich 0.161025 0.001539 1.000000 0.345080 0.169935 0.314393 0.128123 0.192428 0.339133
Oberösterreich 0.180688 0.132064 0.345080 1.000000 0.234117 0.340700 0.178046 0.179838 0.271356
Salzburg 0.168891 0.026938 0.169935 0.234117 1.000000 0.153182 0.136910 0.153270 0.139731
Steiermark 0.143218 0.099281 0.314393 0.340700 0.153182 1.000000 0.159564 0.148719 0.094488
Tirol 0.127724 0.432460 0.128123 0.178046 0.136910 0.159564 1.000000 0.122826 0.162530
Vorarlberg 0.065947 -0.049306 0.192428 0.179838 0.153270 0.148719 0.122826 1.000000 0.018843
Wien 0.218916 0.100833 0.339133 0.271356 0.139731 0.094488 0.162530 0.018843 1.000000